#include "..\include_eapi_header.h"
//#include <atlbase.h>
//#include <atlcom.h>
//#include <ShlObj.h>
//#include <comutil.h>
//#include <string>
//#include<atlcom.h>
//#include <iostream>
//#include <ShObjIdl.h>
//#include <comdef.h>
//#include <ShlObj.h>     // Shell API
//#include <atlcomcli.h>  // CComPtr & Co.
//#include <string> 
//#include <iostream> 
//#include <system_error>

//// Throw a std::system_error if the HRESULT indicates failure.
//template< typename T >
//void ThrowIfFailed(HRESULT hr, T&& msg)
//{
//	if (FAILED(hr))
//		throw std::system_error{ hr, std::system_category(), std::forward<T>(msg) };
//}
//
//// RAII wrapper to initialize/uninitialize COM
//struct CComInit
//{
//	CComInit() { ThrowIfFailed(::CoInitialize(nullptr), "CoInitialize failed"); }
//	~CComInit() { ::CoUninitialize(); }
//	CComInit(CComInit const&) = delete;
//	CComInit& operator=(CComInit const&) = delete;
//};
//
//// Query an interface from the desktop shell view.
//void FindDesktopFolderView(REFIID riid, void** ppv, std::string const& interfaceName)
//{
//	CComPtr<IShellWindows> spShellWindows;
//	ThrowIfFailed(
//		spShellWindows.CoCreateInstance(CLSID_ShellWindows),
//		"Failed to create IShellWindows instance");
//
//	CComVariant vtLoc(CSIDL_DESKTOP);
//	CComVariant vtEmpty;
//	long lhwnd;
//	CComPtr<IDispatch> spdisp;
//	ThrowIfFailed(
//		spShellWindows->FindWindowSW(
//			&vtLoc, &vtEmpty, SWC_DESKTOP, &lhwnd, SWFO_NEEDDISPATCH, &spdisp),
//		"Failed to find desktop window");
//
//	CComQIPtr<IServiceProvider> spProv(spdisp);
//	if (!spProv)
//		ThrowIfFailed(E_NOINTERFACE, "Failed to get IServiceProvider interface for desktop");
//
//	CComPtr<IShellBrowser> spBrowser;
//	ThrowIfFailed(
//		spProv->QueryService(SID_STopLevelBrowser, IID_PPV_ARGS(&spBrowser)),
//		"Failed to get IShellBrowser for desktop");
//
//	CComPtr<IShellView> spView;
//	ThrowIfFailed(
//		spBrowser->QueryActiveShellView(&spView),
//		"Failed to query IShellView for desktop");
//
//	ThrowIfFailed(
//		spView->QueryInterface(riid, ppv),
//		"Could not query desktop IShellView for interface " + interfaceName);
//}void ToggleDesktopIcons()
//{
//	CComPtr<IFolderView2> spView;
//	FindDesktopFolderView(IID_PPV_ARGS(&spView), "IFolderView2");
//
//	DWORD flags = 0;
//	ThrowIfFailed(
//		spView->GetCurrentFolderFlags(&flags),
//		"GetCurrentFolderFlags failed");
//	ThrowIfFailed(
//		spView->SetCurrentFolderFlags(FWF_NOICONS, flags ^ FWF_NOICONS),
//		"SetCurrentFolderFlags failed");
//}
//
//void test()
//{
//	try
//	{
//		CComInit init;
//
//		ToggleDesktopIcons();
//
//		std::cout << "Desktop icons have been toggled.\n";
//	}
//	catch (std::system_error const& e)
//	{
//		std::cout << "ERROR: " << e.what() << ", error code: " << e.code() << "\n";
//		return ;
//	}
//
//	return ;
//}

//void FindDesktopFolderView(REFIID riid, void** ppv, const std::string_view& interfaceName)
//{
//	CComPtr <IShellWindows> spShellWindows;
//	if (FAILED(spShellWindows.CoCreateInstance(CLSID_ShellWindows)))
//	{
//		return;
//	}
//
//
//	CComVariant vtLoc(CSIDL_DESKTOP);
//	CComVariant vtEmpty;
//	long lhwnd;
//	CComPtr<IDispatch> spdisp;
//	if (FAILED(spShellWindows->FindWindowSW(
//		&vtLoc, &vtEmpty, SWC_DESKTOP, &lhwnd, SWFO_NEEDDISPATCH, &spdisp)))
//	{
//		return;
//	}
//	CComQIPtr<IServiceProvider> spProv(spdisp);
//	if (!spProv) {
//		return;
//	}
//	CComPtr<IShellBrowser> spBrowser;
//	if (FAILED(spProv->QueryService(SID_STopLevelBrowser, IID_PPV_ARGS(&spBrowser))))
//	{
//		return;
//	}
//
//	CComPtr<IShellView> spView;
//	if (FAILED(spBrowser->QueryActiveShellView(&spView)))
//	{
//		return;
//	}
//
//
//	if (FAILED(spView->QueryInterface(riid, ppv)))
//	{
//		return;
//	}
//}

EAPI_EXTERN_C void eapi_HideDesktopIcon_57_eapi(PMDATA_INF pRetData, INT nArgCount, PMDATA_INF pArgInf)
{
	HWND hWnd = FindWindowW(L"Progman", L"Program Manager");
	if (hWnd)
	{
		ShowWindow(hWnd, SW_SHOW);
		UpdateWindow(hWnd);
	}
	else {
		hWnd = FindWindowW(L"WorkerW", NULL);
		ShowWindow(hWnd, SW_SHOW);
		UpdateWindow(hWnd);
	}

}

